from django.db import models

# Create your models here.

# 部门表
class DepartmentModel(models.Model):
    department = models.CharField('部门名称', max_length=20, default='')

    def __str__(self):
        return self.department

    class Meta:
        db_table = 'department_tb'
        verbose_name_plural = '部门模型类'

# 职级表
class RankModel(models.Model):
    rank = models.CharField('职级名称', max_length=20, default='')

    def __str__(self):
        return self.rank

    class Meta:
        db_table = 'rank_tb'
        verbose_name_plural = '职级模型类'

# 岗位表
class PostModel(models.Model):
    posts = models.CharField('岗位名称', max_length=20, default='')

    def __str__(self):
        return self.posts

    class Meta:
        db_table = 'posts_tb'
        verbose_name_plural = '岗位模型类'

# 权限表
class PermissionModel(models.Model):
    permission = models.CharField('拥有权限', max_length=20, default='')
    per_url = models.CharField('路由', max_length=20, default='')

    def __str__(self):
        return self.permission

    class Meta:
        db_table = 'permission_tb'
        verbose_name_plural = '权限模型类'


# 角色表
class RoleModel(models.Model):
    role = models.CharField('角色表', max_length=20, default='')
    per_id = models.ForeignKey(to=PermissionModel,on_delete=models.CASCADE,verbose_name='所属权限')

    def __str__(self):
        return self.role

    class Meta:
        db_table = 'role_tb'
        verbose_name_plural = '角色模型类'

# 用户表
class UserModel(models.Model):
    username = models.CharField('用户名',max_length=64,default='')
    account = models.CharField('账号',max_length=20,default='')
    password = models.CharField('密码',max_length=20,default='')
    mobile = models.CharField('手机号',max_length=13,default='')
    mail = models.CharField('邮箱', max_length=30, default='')
    role_id =models.ForeignKey(to=RoleModel,on_delete=models.CASCADE,verbose_name='所属角色',default=3)
    department_id = models.ForeignKey(to=DepartmentModel, on_delete=models.CASCADE, verbose_name='所属部门')
    rank_id = models.ForeignKey(to=RankModel, on_delete=models.CASCADE, verbose_name='所属职级')
    posts_id = models.ForeignKey(to=PostModel, on_delete=models.CASCADE, verbose_name='所属岗位')
    state = models.CharField('员工状态',max_length=10,default='1 在职 2 出差 3 请假')

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user_tb'
        verbose_name_plural = '用户模型类'

# 车辆信息表
class CarMessageModel(models.Model):
    car_name = models.CharField('车辆名称',max_length=20,default='')
    car_type = models.CharField('车辆类型',max_length=20,default='')
    car_num = models.CharField('车牌号',max_length=20,default='')

    class Meta:
        db_table = 'car_message_tb'
        verbose_name_plural = '车辆信息表'

    def __str__(self):
        return self.car_name
